package com.crape.topic.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.crape.common.exceptions.DAOException;
import com.crape.common.ibatis.SqlMapClientDaoSupportEx;
import com.crape.common.model.Article;
import com.crape.common.model.ArticleIndex;
import com.crape.topic.dao.IArticleIndexDAO;

public class ArticleIndexDAOImpl extends SqlMapClientDaoSupportEx implements IArticleIndexDAO {

	@Override
	public ArticleIndex getArticleIndexByArticleid(Long articleid) throws DAOException {
		if (articleid == null) {
			return null;
		}
		return (ArticleIndex) this.queryObject("getArticleIndexByArticleid", articleid);
	}

	@Override
	public void insertArticleIndex(ArticleIndex articleIndex) throws DAOException {
		if (articleIndex == null) {
			return;
		}
		this.insert("insertArticleIndex", articleIndex);
	}

	@Override
	public void updateArticleIndex(ArticleIndex articleIndex) throws DAOException {
		if (articleIndex == null) {
			return;
		}
		this.update("updateArticleIndex", articleIndex);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Article> getIndexArticles(Long accountid, Long articleid, Integer indexType, Integer status, Integer startIndex, Integer pageSize)
			throws DAOException {
		if (startIndex == null || pageSize == null || pageSize == 0) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accountid", accountid);
		params.put("articleid", articleid);
		params.put("indexType", indexType);
		params.put("status", status);
		params.put("startIndex", startIndex);
		params.put("pageSize", pageSize);
		return (List<Article>) this.queryList("getIndexArticles", params);
	}

	@Override
	public Long countIndexArticles(Long accountid, Long articleid, Integer indexType, Integer status) throws DAOException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("accountid", accountid);
		params.put("articleid", articleid);
		params.put("indexType", indexType);
		params.put("status", status);
		return (Long) this.queryObject("countIndexArticles", params);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Article> getIndexShowArticles(Integer indexType, Integer showNum) throws DAOException {
		if (indexType == null || showNum == null) {
			return null;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("indexType", indexType);
		params.put("showNum", showNum);
		return (List<Article>) this.queryList("getIndexShowArticles", params);
	}

}
